Fk:loadTranslationTable{
  ["plum__yuming"] = "育名",
  [":plum__yuming"] = "摸牌阶段，你可展示任意张不同类别的手牌并多摸等量牌，然后可将至多四张手牌交给一名其他角色。若等效于发动“好施”，你可获得场上一张牌。",

  ["#plum__yuming-choose"] = "育名：可展示任意张不同类别的手牌并多摸等量牌",
  ["#plum__yuming-give"] = "育名：可将至多四张手牌交给一名其他角色",
  ["#plum__yuming-obtain"] = "育名：可获得场上一张牌",
}

local yuming = fk.CreateSkill{
  name = "plum__yuming"
}

--- show and draw
yuming:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(yuming.name) and player:getHandcardNum() > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local _, ret = room:askToUseActiveSkill(player, {
      skill_name = "plum__yuming_choose",
      cancelable = true,
      prompt = "#plum__yuming-choose"
    })
    if not ret or #ret.cards == 0 then return end
    event:setCostData(self, { cards = ret.cards })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    if not cards or player.dead then return end
    data.n = data.n + #cards
    data.extra_data = data.extra_data or {}
    data.extra_data.plum__yuming = { n = 2 }
    room:showCards(cards, player)
  end
})

--- give
yuming:addEffect(fk.AfterDrawNCards, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(yuming.name) and player:usedSkillTimes(yuming.name, Player.HistoryPhase) > 0 and #player.room.alive_players > 1
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local players, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = 1,
      max_card_num = 4,
      max_num = 1,
      min_num = 1,
      skill_name = yuming.name,
      targets = room:getOtherPlayers(player, false),
      cancelable = true,
      pattern = ".|.|.|hand",
      prompt = "#plum__yuming-give"
    })
    if #players ~= 1 or #cards == 0 then return end
    data.extra_data.plum__yuming.hand = player:getHandcardNum()
    data.extra_data.plum__yuming.give = #cards
    data.extra_data.plum__yuming.toMin = table.every(room.alive_players, function(p) return p:getHandcardNum() >= players[1]:getHandcardNum() end)
    event:setCostData(self, { to = players[1], cards = cards })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local to = event:getCostData(self).to ---@type ServerPlayer
    local cards = event:getCostData(self).cards ---@type integer[]
    local room = player.room
    room:moveCardTo(cards, Player.Hand, to, fk.ReasonGive, yuming.name, nil, false, player)
    if player.dead then return end
    if data.extra_data.plum__yuming.n == 2 and data.extra_data.plum__yuming.hand >= 5
    and data.extra_data.plum__yuming.give == data.extra_data.plum__yuming.hand // 2
    and data.extra_data.plum__yuming.toMin then
      local targets = table.filter(room.alive_players, function(p) return #p:getCardIds("ej") > 0 end)
      if #targets > 0 then
        local tos = room:askToChoosePlayers(player, {
          targets = targets,
          min_num = 1,
          max_num = 1,
          skill_name = yuming.name,
          cancelable = true,
          prompt = "#plum__yuming-obtain"
        })
        local card = room:askToChooseCard(player, {
          target = tos[1],
          flag = "ej",
          skill_name = yuming.name,
          prompt = "#plum__yuming-obtain"
        })
        room:moveCardTo(card, Player.Hand, player, fk.ReasonPrey, yuming.name, nil, true, player)
      end
    end
  end
})

return yuming